/*
  Copyright 2007 Anders Båtstrand

      Licensed under the Apache License, Version 2.0 (the "License");
      you may not use this file except in compliance with the License.
      You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

      Unless required by applicable law or agreed to in writing, software
      distributed under the License is distributed on an "AS IS" BASIS,
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      See the License for the specific language governing permissions and
      limitations under the License.

 */

package org.dyndns.anderlin.jmplayer.model;

import javax.persistence.*;

/**
 * Opus 111, BWV 266 etc
 */
@Entity
public class PieceNumber extends JmplayerObject {

    @ManyToOne
    @JoinColumn(nullable = false)
    private Piece piece;

    /**
     * The piece numbering method. opus, BWV etc
     */
    @ManyToOne
    @JoinColumn(nullable = false)
    private PieceNumbering pieceNumbering;

    /**
     * The number.
     */
    @Basic
    @Column(nullable = false)
    private Integer number;

    /**
     * The sub number, if any
     */
    @Basic
    private Integer subNumber;


    public PieceNumbering getPieceNumbering() {
        return pieceNumbering;
    }

    public void setPieceNumbering(PieceNumbering pieceNumbering) {
        this.pieceNumbering = pieceNumbering;
    }

    public Integer getSubNumber() {
        return subNumber;
    }

    public void setSubNumber(Integer subNumber) {
        this.subNumber = subNumber;
    }

    public Integer getNumber() {
        return number;
    }

    public void setNumber(Integer number) {
        this.number = number;
    }


    public Piece getPiece() {
        return piece;
    }

    public void setPiece(Piece piece) {
        this.piece = piece;
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        PieceNumber that = (PieceNumber) o;

        if (number != null ? !number.equals(that.number) : that.number != null) return false;
        if (pieceNumbering != null ? !pieceNumbering.equals(that.pieceNumbering) : that.pieceNumbering != null)
            return false;

        return true;
    }

    public int hashCode() {
        int result;
        result = (pieceNumbering != null ? pieceNumbering.hashCode() : 0);
        result = 31 * result + (number != null ? number.hashCode() : 0);
        return result;
    }


    @Override
    public String toString() {
        return pieceNumbering + " " + number;
    }
}
